﻿//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: ObjectStates.cs
//
//  Description: States of a persistent in memory.
// 
//--------------------------------------------------------------------------

using System;

namespace Chili.Opf3
{
	/// <summary>Defines the state of a persistent object in memory.</summary>
	/// <remarks>
	/// <para>This enumeration represents the state of a persistent object. It is used
	/// internally to decide whether to insert, update or delete an object to/from the
	/// storage.
	/// </para>
	/// <para>
	/// <strong>Attention:</strong> Modifying properties using this enumeration could
	/// cause unexpected behavior when saving objects.
	/// </para>
	/// </remarks>
	/// <example>
	///     The following example shows how to request the <see cref="ObjectInfo">ObjectInfo</see> instance of the
	///     <see cref="ISelfContainingObject">ISelfContainingObject</see> to determine whether the object has been 
	///     loaded from the storage.
	///     <code lang="CS">
	/// [Persistent("USER")]
	/// public class User : ISelfContainingObject
	/// {
	///     // ... Other properties and fields.
	/// }
	///  
	/// // ... Other code
	///  
	/// // Loads a user object from the storage.
	/// User user = context.GetObject&lt;User&gt;("Id = {0}", "1");
	/// // Checks if the object has been loaded.
	/// if (user.ObjectInfo.ObjectState == ObjectStates.Loaded)
	/// {
	///     Debug.WriteLine("Object has been loaded.");
	/// }
	///     </code>
	/// </example>
	[Serializable]
	public enum ObjectStates
	{
		/// <summary>
		/// Persistent objects with this state aren't loaded, saved or deleted. They have been recently created in memory.
		/// </summary>
		None,
		/// <summary>
		/// Persistent objects with this state have been loaded from the storage.
		/// </summary>
		Loaded,
		/// <summary>
		/// Persistent objects with this state have been inserted into the storage. The framework is doing an
		/// update if the persistent is saved again.
		/// </summary>
		Inserted,
		/// <summary>
		/// Persistent objects with this state have been updated in the storage.
		/// </summary>
		Updated,
		/// <summary>
		/// Persistent objects with this state are no longer available in the storage. They have
		/// been deleted. The framework is doing an insert if they are saved the next time.
		/// </summary>
		Deleted
	}
}
